package edu.wfu.preparedDishes.commodity.service.impl;

import edu.wfu.preparedDishes.commodity.entity.CartVo;
import edu.wfu.preparedDishes.commodity.entity.commodityVo;
import edu.wfu.preparedDishes.common.utils.PageUtils;
import edu.wfu.preparedDishes.common.utils.Query;
import edu.wfu.preparedDishes.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.wfu.preparedDishes.commodity.dao.CartDao;
import edu.wfu.preparedDishes.commodity.entity.CartEntity;
import edu.wfu.preparedDishes.commodity.service.CartService;


@Service("cartService")
public class CartServiceImpl extends ServiceImpl<CartDao, CartEntity> implements CartService {

    @Autowired
    private CartDao dao;


    @Override
    public Integer getNum(String userId) {
        Integer num = dao.getNum(userId);
        
        return num;
    }

    @Override
    public List<CartVo> queryList(int pageSize, int offset, String userId) {
        return dao.queryListWithPagination(pageSize,offset,userId);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CartEntity> page = this.page(
                new Query<CartEntity>().getPage(params),
                new QueryWrapper<CartEntity>()
        );
        return new PageUtils(page);
    }

    @Override
    public void add(String id) {
        dao.add(id);
    }

    @Override
    public void addMore(String id, Integer num) {
        dao.addMore(id,num);
    }

    @Override
    public void reduce(String id) {
        dao.reduce(id);
    }

    @Override
    public Integer sum(String userId) {

        return dao.sum(userId);
    }

    @Override
    public CartEntity isHave(String skuId,String userId) {

         return dao.isHaveBySkuId(skuId,userId);

    }


}